package com.twu.biblioteca;

import java.util.NoSuchElementException;

public class BibliotecaApp {

    public static void main(String[] args) {
        BookList bookList = new BookList();
        bookList.initBookList();
        MainMenu activeMenu = new MainMenu(null, System.in);

        System.out.println("+++++++ "+ new WelcomeMessage().getMessage() +" ++++++++1");
        while(true) {
            int userSelection = 0;

            try {
                userSelection = activeMenu.mainMenuLauncher();
            }
            catch (NoSuchElementException | NumberFormatException e) {
                System.out.println("your entry is not valid. Select a valid option!:");
            }

            switch (userSelection) {

                case 1:
                    System.out.println(bookList.getAvailableBookList());
                    break;

                case 2:
                    bookList.getAvailableBookList();
                    try {
                        Book book = bookList.get(activeMenu.bookCheckout());
                        book.setStatus("checkedOut");
                        System.out.println("Thank you! Enjoy the book");
                    }
                    catch(IndexOutOfBoundsException f) {
                        System.out.println("That book is not available");
                    }

                    break;

                case 3:
                    bookList.getAvailableBookList();
                    try {
                        Book book = bookList.get(activeMenu.returnBook());
                        book.setStatus("available");
                        System.out.println("Thank you for returning the book");
                    }
                    catch(IndexOutOfBoundsException g) {
                        System.out.println("That is not a valid book to return");
                    }
                    break;

                case 9:
                    System.out.println("You are exiting Biblioteca. Good bye");
                    System.exit(0);
                    break;
            }

        }

    }
}
